using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using Ajax;

namespace BA.Chat
{
    public class ChatEngineUser
    {
        // Fields
        private ChatEngine c = new ChatEngine();
        protected static ArrayList cArray = new ArrayList();

        // Methods
        [AjaxMethod]
        public void AddCustomer(string sUser)
        {
            string cAddText = sUser;
            cArray.Add(cAddText);
            if (cArray.Count > 200)
            {
                cArray.RemoveRange(0, 10);
            }
        }

        public bool CheckUser(string Username)
        {
            return cArray.Contains(Username);
        }

        [AjaxMethod]
        public void clean()
        {
            cArray.Clear();
        }

        [AjaxMethod]
        public string GetAllUsers()
        {
            string cResponse = "";

            for (int i = 0; i < cArray.Count; i++)
            {
                cResponse = cResponse + string.Format("<a href=\"default.aspx?pid=cp_profileview&userid={0}\" target=\"_blank\">{0}</a><br>", cArray[i].ToString());
            }

            return cResponse;
        }

        [AjaxMethod]
        public void SignOut(string Username)
        {
            if (cArray.Contains(Username))
            {
                cArray.Remove(Username);
                this.c.leaveRoom(Username);
            }
        }

    }
}
